package com.gzk.service.impl;

import com.baomidou.mybatisplus.service.impl.ServiceImpl;
import com.gzk.domain.ProductStore;
import com.gzk.mapper.ProductStoreMapper;
import com.gzk.service.IProductStoreService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.Map;

/**
 * <p>
 *  服务实现类
 * </p>
 *
 * @author jake.Chen
 * @since 2022-02-07
 */
@Service
public class ProductStoreServiceImpl extends ServiceImpl<ProductStoreMapper, ProductStore> implements IProductStoreService {

    @Autowired
    private ProductStoreMapper productStoreMapper;

    @Override
    public Long getStoreByProductId(Long id) {
        return productStoreMapper.selectStore(id);
    }

    @Override
    @Transactional
    public void reduceStore(Map<String, Long> map) {
        Long store = productStoreMapper.selectStore(map.get("productId"));
        store = store - map.get("number");
        //根据商品id修改库存
        productStoreMapper.updateStore(map.get("productId"),store);
    }
}
